package com.jld;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

public class test {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Collections.addAll(list, "张三-15", "张思-16", "王五-20", "赵说-30", "李松-50", "张一-22");
        //filter过滤
        list.stream().filter(s -> s.startsWith("张")).forEach(s -> System.out.println(s));
        //.map 转换流中数据类型 流原来的数据类型String->要转成的类型 int
        //
        list.stream().map(new Function<String, Integer>() {

            @Override
            public Integer apply(String s) {
                String[] arr = s.split("-");
                String ageString = arr[1];//数组1索引获取年龄
                int age = Integer.parseInt(ageString);

                return age;
            }
        }).forEach(s -> System.out.println(s));

        System.out.println("------------------------------------------");

        list.stream().map(s -> Integer.parseInt(s.split("-")[1]))
                .forEach(s -> System.out.println(s));
    }
}
